<?php

namespace app\model\posts;

use app\model\user\User;
use crmeb\basic\BaseModel;
use crmeb\traits\ModelTrait;

/**
 * 帖子
 * Class Posts
 * @package app\model\posts
 */
class Posts extends BaseModel
{
    use ModelTrait;

    /**
     * 表明
     * @var string
     */
    protected $name = 'posts';
    protected $insert = ['add_time'];
    protected $autoWriteTimestamp = true;
    /**
     * 主键
     * @var string
     */
    protected $pk = 'id';

    protected function setAddTimeAttr($value)
    {
        return time();
    }

    protected function getSliderImageAttr($value){
        return json_decode($value, true);
    }

    public function user() {
        return $this->hasone(User::class, 'uid', 'user_id')->bind(['nickname','avatar']);
    }

    public function postType() {
        return $this->hasone(\app\model\crud\PostsTypes::class,'id','post_type')->bind(['post_type_name']);
    }
}